package pers.cz.io;

import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * @program: PostGirl-panent
 * @description: 根据url获取资源
 * @author: Cheng Zhi
 * @create: 2022-06-29 17:36
 **/
public class UrlResource implements Resource {

    private URL url;

    public UrlResource(URL url) {
        this.url = url;
    }

    @Override
    public InputStream getInputStream() throws Exception {
        URLConnection urlConnection = url.openConnection();
        urlConnection.connect();
        return urlConnection.getInputStream();
    }

    @Override
    public FileInputStream getFileInputStream() throws Exception {
        return new FileInputStream(url.getPath());
    }


}
